<template>
  <j-modal
    :title="title"
    :width="1200"
    :visible="visible"
    :maskClosable="false"
    :confirmLoading="confirmLoading"
    switchFullscreen
    @ok="handleOk"
    @cancel="handleCancel">
    <a-spin :spinning="confirmLoading">
      <!-- 主表单区域 -->
      <a-form :form="form">
        <a-row>

          <a-col :xs="24" :sm="12">
            <a-form-item label="账单日期" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-date placeholder="请选择账单日期" v-decorator="['date']" :trigger-change="true" style="width: 100%"/>
            </a-form-item>
          </a-col>
          <a-col :xs="24" :sm="12">
            <a-form-item label="收款方账户名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['payeeName']" placeholder="请输入收款方账户名称"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xs="24" :sm="12">
            <a-form-item label="汇总金额(单位元)" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input-number v-decorator="['money']" placeholder="请输入汇总金额(单位元)" style="width: 100%"/>
            </a-form-item>
          </a-col>
          <a-col :xs="24" :sm="12">
            <a-form-item label="收款方开户行号" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['payeeBankDeposit']" placeholder="请输入收款方开户行号"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xs="24" :sm="12">
            <a-form-item label="条数" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input-number v-decorator="['count']" placeholder="请输入返回查询的结果条数" style="width: 100%"/>
            </a-form-item>
          </a-col>
          <a-col :xs="24" :sm="12">
            <a-form-item label="收款方账号" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['payeeAccount']" placeholder="请输入收款方账号"></a-input>
            </a-form-item>
          </a-col>
<!--          <a-col :xs="24" :sm="12">-->
<!--            <a-form-item label="所属公司ID" :labelCol="labelCol" :wrapperCol="wrapperCol">-->
<!--              <a-input v-decorator="['companyId']" placeholder="请输入所属公司ID"></a-input>-->
<!--            </a-form-item>-->
<!--          </a-col>-->

        </a-row>
      </a-form>

      <!-- 子表单区域 -->
      <a-tabs v-model="activeKey" @change="handleChangeTabs">
        <a-tab-pane tab="对账单详情" :key="refKeys[0]" :forceRender="true">
          <j-editable-table
            :ref="refKeys[0]"
            :loading="statementAccountDetailsTable.loading"
            :columns="statementAccountDetailsTable.columns"
            :dataSource="statementAccountDetailsTable.dataSource"
            :maxHeight="300"
            :rowNumber="true"
            :rowSelection="true"
            :actionButton="true"/>
        </a-tab-pane>

      </a-tabs>

    </a-spin>
  </j-modal>
</template>

<script>

  import pick from 'lodash.pick'
  import { FormTypes,getRefPromise } from '@/utils/JEditableTableUtil'
  import { JEditableTableMixin } from '@/mixins/JEditableTableMixin'
  import { validateDuplicateValue } from '@/utils/util'
  import JDate from '@/components/jeecg/JDate'

  export default {
    name: 'StatementAccountModal',
    mixins: [JEditableTableMixin],
    components: {
      JDate,
    },
    data() {
      return {
        labelCol: {
          xs: { span: 24 },
          sm: { span: 6 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        labelCol2: {
          xs: { span: 24 },
          sm: { span: 3 },
        },
        wrapperCol2: {
          xs: { span: 24 },
          sm: { span: 20 },
        },
        // 新增时子表默认添加几行空数据
        addDefaultRowNum: 1,
        validatorRules: {
        },
        refKeys: ['statementAccountDetails', ],
        tableKeys:['statementAccountDetails', ],
        activeKey: 'statementAccountDetails',
        // 对账单详情
        statementAccountDetailsTable: {
          loading: false,
          dataSource: [],
          columns: [
            {
              title: '商户号',
              key: 'partnerNo',
              type: FormTypes.input,
              width:"200px",
              placeholder: '请输入${title}',
              defaultValue: '',
            },
            {
              title: '商户订单号',
              key: 'outTradeNo',
              type: FormTypes.input,
              width:"200px",
              placeholder: '请输入${title}',
              defaultValue: '',
            },
            {
              title: '交易描述',
              key: 'tradeMessage',
              type: FormTypes.input,
              width:"200px",
              placeholder: '请输入${title}',
              defaultValue: '',
            },
            {
              title: '支付时间',
              key: 'tradeFinishTime',
              type: FormTypes.date,
              width:"200px",
              placeholder: '请输入${title}',
              defaultValue: '',
            },
            {
              title: '交易状态',
              key: 'tradeState',
              type: FormTypes.select,
              dictCode:"",
              width:"200px",
              placeholder: '请输入${title}',
              defaultValue: '',
            },
            {
              title: '订单总金额',
              key: 'totalFee',
              type: FormTypes.input,
              width:"200px",
              placeholder: '请输入${title}',
              defaultValue: '',
            },
            // {
            //   title: '支付的订单IDS',
            //   key: 'orderIds',
            //   type: FormTypes.input,
            //   width:"200px",
            //   placeholder: '请输入${title}',
            //   defaultValue: '',
            // },
            {
              title: '订单类型',
              key: 'orderType',
              type: FormTypes.input,
              width:"200px",
              placeholder: '请输入${title}',
              defaultValue: '',
            },
            {
              title: '支付方式',
              key: 'tradeType',
              type: FormTypes.input,
              width:"200px",
              placeholder: '请输入${title}',
              defaultValue: '',
            },
            {
              title: '支付订单号',
              key: 'transactionId',
              type: FormTypes.input,
              width:"200px",
              placeholder: '请输入${title}',
              defaultValue: '',
            },
            {
              title: '收款方账号',
              key: 'payeeAccount',
              type: FormTypes.input,
              width:"200px",
              placeholder: '请输入${title}',
              defaultValue: '',
            },
            // {
            //   title: '更新日期',
            //   key: 'updateTime',
            //   type: FormTypes.date,
            //   width:"200px",
            //   placeholder: '请输入${title}',
            //   defaultValue: '',
            // },
            // {
            //   title: '所属公司ID',
            //   key: 'companyId',
            //   type: FormTypes.input,
            //   width:"200px",
            //   placeholder: '请输入${title}',
            //   defaultValue: '',
            // },
          ]
        },
        url: {
          add: "/zcgl/statementAccount/add",
          edit: "/zcgl/statementAccount/edit",
          statementAccountDetails: {
            list: '/zcgl/statementAccount/queryStatementAccountDetailsByMainId'
          },
        }
      }
    },
    methods: {
      getAllTable() {
        let values = this.tableKeys.map(key => getRefPromise(this, key))
        return Promise.all(values)
      },
      /** 调用完edit()方法之后会自动调用此方法 */
      editAfter() {
        let fieldval = pick(this.model,'date','payeeName','money','payeeBankDeposit','count','payeeAccount','companyId')
        this.$nextTick(() => {
          this.form.setFieldsValue(fieldval)
        })
        // 加载子表数据
        if (this.model.id) {
          let params = { id: this.model.id }
          this.requestSubTableData(this.url.statementAccountDetails.list, params, this.statementAccountDetailsTable)
        }
      },
      /** 整理成formData */
      classifyIntoFormData(allValues) {
        let main = Object.assign(this.model, allValues.formValue)

        return {
          ...main, // 展开
          statementAccountDetailsList: allValues.tablesValue[0].values,
        }
      },
      validateError(msg){
        this.$message.error(msg)
      },
     popupCallback(row){
       this.form.setFieldsValue(pick(row,'date','payeeName','money','payeeBankDeposit','count','payeeAccount','companyId'))
     },

    }
  }
</script>

<style scoped>
</style>